package com.yan_jiu_sheng.LeetCodeHot100.AC;

/**
 * https://leetcode.cn/problems/invert-binary-tree/?envType=study-plan-v2&envId=top-100-liked
 * 通过
 *
 * @author yulongTian
 * @create 2024-06-01 14:09
 */
public class Test38 {
    public static void main(String[] args) {

    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public TreeNode invertTree(TreeNode root) {
        latterTrval(root);
        return root;
    }

    public void latterTrval(TreeNode root) {
        if (root == null) {
            return;
        }

        //左
        latterTrval(root.left);
        //右
        latterTrval(root.right);
        //根
        TreeNode temp = root.right;
        root.right = root.left;
        root.left = temp;
    }

}
